Skip to content

Conversation

HansOlsson
Copy link
Collaborator

To ensure that current MSL is valid and that users can update.

Closes #3719

Note that in addition to the changes in the issue reordered the items and changed "must" to "should" for the deprecated semantic, and clearly indicated that the exception is the deprecated case.
(Having a "must"-requirement and then have exceptions for it just seems wrong.)

…valid and that users can update.

Closes modelica#3719

Note that in addition to the changes in the issue reordered the items and changed "must" to "should" for the deprecated semantic,
and clearly indicated that the exception is the deprecated case.
(Having a "must"-requirement and then have exceptions for it just seems wrong.)
@HansOlsson HansOlsson linked an issue Sep 30, 2025 that may be closed by this pull request
@HansOlsson HansOlsson added this to the 2025-October milestone Oct 1, 2025
Comment on lines +231 to +232
External functions should be explicitly declared with \lstinline!pure! or \lstinline!impure!.
The case without the keyword is deprecated semantics described in the next item.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I saw your comment, but I don't agree that this is the style in which the specification is written. I believe this is how we do it:

Suggested change
External functions should be explicitly declared with \lstinline!pure! or \lstinline!impure!.
The case without the keyword is deprecated semantics described in the next item.
External functions shall be explicitly declared with \lstinline!pure! or \lstinline!impure!.
A deprecated semantics is that an external function declared with neither \lstinline!pure! nor \lstinline!impure! is handled according to the next item.

Copy link
Collaborator Author

@HansOlsson HansOlsson Oct 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The usual specification define of shall/should is rfc2119 - and deprecated mean discouraged, not forbidden.
Combined I don't see that one can combine "shall" and deprecated in that way.

Modelica Specification could be different, but I could not find any such uses of deprecated combined with shall/should/must/may but instead found:

Copy link
Collaborator

@henrikt-ma henrikt-ma left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The way I read the proposal, a tool should generate a deprecation warning for every function not explicitly declared pure or impure. This makes it hard to make sense of the "normally" rule in the beginning.

Am I getting the intention right if I think the goal is to:

  • Lack of explicit purity of an external function is deprecated.
  • For a function not declared impure, it is deprecated to call an external function not declared pure. (Hence, making the impure of an external function explicit will address one deprecation warning without leading to new ones.)
  • For a function without explicit purity, it is deprecated to call any function declared impure. (Making the impure of an external function explicit will cause an error if called from a function explicitly declared pure.)
  • A function is assumed impure in the following cases (applied recursively):
    • It is declared impure
    • It is an external function without explicit purity
    • It calls another function assumed impure
  • (A function not assumed impure is assumed pure.)

What I am trying to capture above is that the deprecation rules have only to do with the explicit declaration of functions as pure or impure, whereas the reasoning about impure behavior is based on rules which are formulated so that they make sense regardless of deprecated (lack of) purity declaration.

Co-authored-by: Henrik Tidefelt <[email protected]>
@HansOlsson
Copy link
Collaborator Author

The way I read the proposal, a tool should generate a deprecation warning for every function not explicitly declared pure or impure.

That wasn't the intention, the new semantics was only intended to kick in if:

  • The calling function is declared without pure or impure
  • They call an external function that is not pure (directly or indirectly).

That is a bad combination, and shouldn't be common.
(An impure function should only be called in an impure function (except for ...)).
However, it did occur in MSL - when people started to declare the external functions as impure, and missed the callers due to lack of testing in tools.

The proposed semantics ensure that MSL 4.1.0 is kind of valid. And even more importantly, it also avoids breaking user libraries/models in the same way that rely on those functions in MSL.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Revisit impure - due to errors

2 participants